/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.opu.vcforms.template;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.opu.vcforms.template.hf.HeadersFooters;
import org.opu.vcforms.template.util.Loadable;
import org.opu.vcforms.template.util.SimpleUtil;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

/**
 *
 * @author yura
 */
@Root(name="template")
public class TxtTemplate implements Loadable {

    @Element(required=false, name="headers-footers")
    private HeadersFooters headersFooters;
    @Element
    private Document document;

    public Document getDocument() {
        return document;
    }

    public void setDocument(Document document) {
        this.document = document;
    }

    public HeadersFooters getHeadersFooters() {
        return headersFooters;
    }

    public void setHeadersFooters(HeadersFooters headersFooters) {
        this.headersFooters = headersFooters;
    }

    public boolean haveHeader(){
        return headersFooters != null && !headersFooters.isEmpty();
    }

    @Override
    public void load(InputStream in) throws IOException {
        TxtTemplate read = SimpleUtil.read(in, TxtTemplate.class);
        setDocument(read.getDocument());
        setHeadersFooters(read.getHeadersFooters());
    }

    @Override
    public void store(OutputStream out) throws IOException {
        SimpleUtil.write(out, this);
    }
}
